import RPi.GPIO as GPIO
import time

Left_Black = 11  # IN1 GPIO17
Left_Red = 12     # IN2  GPIO18 PCM_CLK
Right_Black = 13  # IN3 GPIO 27
Right_Red = 15    # IN4 GPIO 22


MOTOR_STATE = None


def setup_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(Left_Black, GPIO.OUT)
    GPIO.setup(Left_Red, GPIO.OUT)
    GPIO.setup(Right_Black, GPIO.OUT)
    GPIO.setup(Right_Red, GPIO.OUT)


def turn_left():
    GPIO.output(Left_Red, False)
    GPIO.output(Left_Black, False)
    GPIO.output(Right_Red, GPIO.HIGH)
    GPIO.output(Right_Black, GPIO.LOW)
    MOTOR_STATE = "TURN_LEFT"


def turn_right():
    GPIO.output(Left_Red, GPIO.HIGH)
    GPIO.output(Left_Black, GPIO.LOW)
    GPIO.output(Right_Red, False)
    GPIO.output(Right_Black, False)
    MOTOR_STATE = "TURN_RIGHT"


def go():
    GPIO.output(Left_Red, GPIO.HIGH)
    GPIO.output(Left_Black, GPIO.LOW)
    GPIO.output(Right_Red, GPIO.HIGH)
    GPIO.output(Right_Black, GPIO.LOW)
    MOTOR_STATE = "GO"


def back():
    GPIO.output(Left_Red, GPIO.LOW)
    GPIO.output(Left_Black, GPIO.HIGH)
    GPIO.output(Right_Red, GPIO.LOW)
    GPIO.output(Right_Black, GPIO.HIGH)
    MOTOR_STATE = "BACK"


setup_gpio()
turn_left()
time.sleep(1)
turn_right()
time.sleep(1)
go()
time.sleep(1)
back()
time.sleep(1)
GPIO.cleanup()
